using System;
using System.Collections;
using System.Threading;

namespace YPing
{
    class Program
    {
        private const int SLEEP_TIME = 3000;

        static void Main(string[] args)
        {
            if (ValidArguments(args))
            {
                foreach (IRequest request in GetRequestItems(args))
                {
                    Console.WriteLine(request.GetResult(args[0]));
                    Thread.Sleep(SLEEP_TIME);
                }
            }
            else
            {
                WriteInstructions();
            }
        }

        private static void WriteInstructions()
        {
            Console.WriteLine("usage YPing [YMID] [-s] [-p] [-t]");
            Console.WriteLine(" YMID: messenger ID");
            Console.WriteLine(" -p: no profile information");
            Console.WriteLine(" -s: no status information");
            Console.WriteLine(" -s: no status information");
        }

        private static bool ValidArguments(string[] args)
        {
            if (args.Length == 0)
            {
                return false;
            }

            return true;
        }

        private static IEnumerable GetRequestItems(string[] args)
        {
            if (!FindArgument(args, "-p"))
            {
                yield return new Profile();
            }

            if (!FindArgument(args, "-s"))
            {
                yield return new Status();
            }

            if (FindArgument(args, "-t"))
            {
                while (true){
                    yield return new Status();
                }
            }
        }

        private static bool FindArgument(string[] args, string value)
        {
            foreach (string argument in args)
            {
                if (argument.Equals(value))
                {
                    return true;
                }
            }
            return false;
        }
    }
}

